#-*- coding: utf-8 -*-

from PySide2 import QtGui
from PySide2 import QtCore
from PySide2 import QtWidgets
import sys

class Demo(QtWidgets.QWidget):
    def __init__(self,parent=None):
        QtWidgets.QWidget.__init__(self,parent)

    def paintEvent(self, *args, **kwargs):
        rect = QtCore.QRect(30, 30, 150, 80)
        painter = QtGui.QPainter(self)
        painter.setPen(QtGui.QColor(0, 160, 230))
        fm = painter.fontMetrics()
        elideText = fm.elidedText("来啊来啊", QtCore.Qt.ElideRight, 200, QtCore.Qt.TextShowMnemonic)
        painter.drawText(rect, QtCore.Qt.AlignCenter, elideText)


if __name__ == "__main__":
    app=QtWidgets.QApplication(sys.argv)
    demo=Demo()
    demo.show()
    sys.exit(app.exec_())